﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClassLibrary
{
    public abstract class DataAccess<T> : IDataAccess<T> 
    {
        const String CONNECTION_STRING = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\FysioDB.mdf;Integrated Security=True;User Instance=True";
        
        protected System.Data.SqlClient.SqlConnection con;
        
        protected void CreateCon()
        { 

            if (con == null)
            {
                con = new System.Data.SqlClient.SqlConnection();
                con.ConnectionString = CONNECTION_STRING;
            }
            con.Open();
        }

        public abstract T Create(T objectToCreate);

        public abstract T Update(T objectToUpdate);

        public abstract bool Delete(T objectToDelete);

        public abstract T Load(int idOfObjectToLoad);

        public abstract List<T> LoadAll();

        protected void EndCon()
        {
            con.Close();
        }
    }
}
